package meta.api.web.file.businesscontrol;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import meta.api.web.common.business.BusiCmnService;
import meta.api.web.file.businessinfo.FileInfo;
import meta.api.web.file.businessinfo.MetadataInfo;
import meta.api.web.file.presentation.form.MetadataForm;

@Transactional
@Component
public class FileMngBusiCtrl {

    @Autowired
    private BusiCmnService busiCmnService;

    @Transactional(readOnly = true)
    public int getFileTotal(MetadataInfo inputMetadata, String userId) {
        return busiCmnService.getFileTotal(inputMetadata, userId);
    }

    @Transactional(readOnly = true)
    public List<FileInfo> getFileList(MetadataInfo inputMetadata, String userId, Integer current, Integer pageSize) {
        return busiCmnService.getFileList(inputMetadata, userId, current, pageSize);
    }

    @Transactional(rollbackFor = Exception.class)
    public void saveFile(FileInfo fileInfo, byte[] fileContent) {
        busiCmnService.saveFile(fileInfo, fileContent);
    }

    @Transactional(readOnly = true)
    public FileInfo getFileByFilename(String filename, String userId) {
        return busiCmnService.getFileByFilename(filename, userId);
    }

    /**
     * 检证文件是否存在
     * 
     * @param filename 文件名
     * @param existFlg null :文件记录存在，忽略文件删除日期是否为NULL<br>
     *                 true :文件逻辑存在，文件删除日期为NULL<br>
     *                 false:文件逻辑删除，文件删除日期不为NULL
     * @return 存在的场合返回true，否则返回false。
     */
    @Transactional(readOnly = true)
    public boolean checkIsFileExisted(String filename, Boolean existFlg) {
        return busiCmnService.checkIsFileExisted(filename, existFlg);
    }

    @Transactional(readOnly = true)
    public boolean checkIsFileOwner(String filename, String userId) {
        return busiCmnService.checkIsFileOwner(filename, userId);
    }

    @Transactional(rollbackFor = Exception.class)
    public void updateFile(String filename, MetadataForm metadataForm, String userId) {
        busiCmnService.updateFile(filename, metadataForm, userId);
    }

    @Transactional(rollbackFor = Exception.class)
    public void deleteFileByFilename(String filename, String userId) {
        busiCmnService.deleteFileByFilename(filename, userId);
    }
}
